"""
Author        yongfa
Date          2022-07-14 13:43:44
LastEditTime  2023-07-26 17:04:33
LastEditors   yongfa
Description   请求参数检验
"""

from flask_restx import reqparse, inputs
from app.extensions.utils.parameters import page_params
from app.extensions.utils.enums import MethodEnum


# 分页参数
get_list_params = page_params.copy()
get_list_params.add_argument('name', type=str, trim=True, location='args', help='名称')
get_list_params.add_argument('label', type=str, trim=True, location='args', help='说明')
get_list_params.add_argument('parent_id', type=int, location='args', help='父级ID')


# 基础
create_base_params = reqparse.RequestParser()
create_base_params.add_argument('name', trim=True, required=True, location='json', help='名称')
create_base_params.add_argument('label', trim=True, required=True, location='json', help='说明')
create_base_params.add_argument('parent_id', type=int, location='json', help='父级ID')


# role创建/修改
role_params = create_base_params.copy()

role_update_params = role_params.copy()
role_update_params.replace_argument('name', trim=True, location='json', help='名称')
role_update_params.replace_argument('label', trim=True, location='json', help='说明')
role_update_params.add_argument('api_ids', type=list, location='json', help='API ID')
role_update_params.add_argument('menu_ids', type=list, location='json', help='菜单ID')
role_update_params.add_argument('dict_ids', type=list, location='json', help='字典ID')
role_update_params.add_argument('user_ids', type=list, location='json', help='用户ID')


role_copy_params = create_base_params.copy()
role_copy_params.add_argument('origin_role_id', type=int, required=True, location='json', help='原角色ID')


# api创建/修改
api_params = create_base_params.copy()
api_params.add_argument('path', type=str, trim=True, required=True, location='json', help='路径')
api_params.add_argument('endpoint', type=str, trim=True, location='json', help='端点')
api_params.add_argument('group', type=str, trim=True, location='json', help='分组')
api_params.add_argument('method', type=str, trim=True, choices=MethodEnum.list_values(), location='json', help='方法')

api_update_params = api_params.copy()
api_update_params.replace_argument('name', trim=True, location='json', help='名称')
api_update_params.replace_argument('label', trim=True, location='json', help='说明')


# menu创建/修改
menu_params = create_base_params.copy()
menu_params.add_argument("path", type=str, trim=True, location='json', help='路径')
menu_params.add_argument("icon", type=str, trim=True, location='json', help='图标')
menu_params.add_argument("component", type=str, trim=True, location='json', help='组件')
menu_params.add_argument("hidden", type=inputs.boolean, trim=True, location='json', help='是否隐藏')
menu_params.add_argument("sort", type=int, trim=True, location='json', help='排序')
menu_params.add_argument("meta", type=dict, location='json', help='元数据')


menu_update_params = menu_params.copy()
menu_update_params.replace_argument('name', trim=True, location='json', help='名称')
menu_update_params.replace_argument('label', trim=True, location='json', help='说明')


permission_params = {
    'get_list': get_list_params,
    'role_params': role_params,
    'role_update_params': role_update_params,
    'role_copy_params': role_copy_params,
    'api_params': api_params,
    'api_update_params': api_update_params,
    'menu_params': menu_params,
    'menu_update_params': menu_update_params
}
